﻿<Window x:Class="WindowManager.SizeSelectionWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WindowManager="clr-namespace:WindowManager"
        Title="SizeSelectionWindow" Height="300" Width="300" ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
        WindowStyle="None" Background="#A4FFFFFF" AllowsTransparency="True" KeyDown="WindowKeyDown" Loaded="SizeSelectionWindowLoaded">
    <Window.Resources>
        <SolidColorBrush x:Key="foregroundBrush" Color="Black" />
        <SolidColorBrush x:Key="selectionBorderBrush" Color="#AF0000FF" />
        <SolidColorBrush x:Key="selectionFillBrush" Color="#A00089FF" />

        <DataTemplate x:Key="ScreenTemplate">
            <Border x:Name="border" Border.BorderThickness="2" Border.BorderBrush="{DynamicResource foregroundBrush}" Border.CornerRadius="2"
              FrameworkElement.Margin="5" FrameworkElement.HorizontalAlignment="Stretch" FrameworkElement.VerticalAlignment="Stretch" />

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsSelected}" Value="True">
                    <Setter Property="Background" TargetName="border" Value="{DynamicResource foregroundBrush}" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

    </Window.Resources>
    <Grid>
        <ItemsControl HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" ItemTemplate="{StaticResource ScreenTemplate}" ItemsSource="{Binding ScreenItems}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Rows="{Binding DataContext.NbRows,RelativeSource={RelativeSource AncestorType=ItemsControl}}" 
                                 Columns="{Binding DataContext.NbColumns,RelativeSource={RelativeSource AncestorType=ItemsControl}}" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>

        <Canvas x:Name="canvas" Background="Transparent" MouseDown="CanvasMouseDown" MouseUp="CanvasMouseUp"
            MouseMove="CanvasMouseMove" x:FieldModifier="private">
            <Rectangle x:Name="rectangle" StrokeThickness="2" Stroke="{DynamicResource selectionBorderBrush}" x:FieldModifier="private"
                 Fill="{DynamicResource selectionFillBrush}" Canvas.Left="-10" />
        </Canvas>
    </Grid>

</Window>